<!DOCTYPE html>

<html lang="en">
<head>
  <title>Test of dynamic stylesheet loading</title>
  <link rel="stylesheet" href="resources/dynamic-stylesheet-insertion-main.css">
  <script src="resources/animation-test-helpers.js" type="text/javascript" charset="utf-8"></script>
  <script type="text/javascript" charset="utf-8">
    
    const expectedValues = [
      // [time, element-id, property, expected-value, tolerance]
      [0.3, "splash", "transform.5", 100, 0.1],
    ];
    
    var controller = {};

    controller.init = function () {
        // put a listener on the initial splash animation
        this.splash = document.getElementById('splash');
        this.splash.addEventListener('webkitAnimationStart', this, false);
        this.splash.addEventListener('webkitAnimationEnd', this, false);

        runAnimationTest(expectedValues, undefined, undefined, true);
    };

    controller.handleEvent = function (event) {
        if (event.type == 'webkitAnimationStart') {
            // pre-load the stylesheet
            var link = document.createElement('link');
            link.rel = 'stylesheet';
            link.href = 'resources/dynamic-stylesheet-insertion-inserted.css';
            document.head.appendChild(link);
        }
    };

    window.addEventListener('DOMContentLoaded', function () {
        controller.init();
    }, false);

  </script>
</head>
<body>
This test performs an animation and then dynamically loads a new stylesheet (which is empty). It should start
animating after a 100ms delay and then stop halfway through the animation at which point we see if it is at the 
correct position. The loading of the stylesheet should not prevent the animation from running.
<div id="splash"></div>
<div id="result">
</div>
</body>
</html>
